package com.shopping.admin.controller.simple;

import com.github.pagehelper.Page;
import com.shopping.common.core.object.ResponseResult;
import com.shopping.common.sp.dto.simple.SimpleDto;
import com.shopping.common.sp.query.simple.SimpleQuery;
import com.shopping.common.sp.vo.simple.SimpleVo;
import com.shopping.service.service.simple.SimpleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例控制器
 */

@Api(tags = "示例接口")
@RestController
@RequestMapping("/admin/simple")
public class SimpleController {

    @Autowired
    private SimpleService simpleService;

    /**
     * 添加示例
     */
    @PostMapping("/add")
    public ResponseResult<Void> addSimple(@RequestBody SimpleDto dto){
        return simpleService.addSimple(dto);
    }

    /**
     * 分页查询列表
     * @param simpleQuery
     * @return
     */
    @PostMapping("/page")
    public ResponseResult<Page<SimpleVo>> simplePage(@RequestBody SimpleQuery simpleQuery){
        return simpleService.simplePage(simpleQuery);
    }

    @PutMapping("/update")
    public ResponseResult<Void> updateSimple(@RequestBody SimpleDto dto){
        return simpleService.updateSimple(dto);
    }

    @DeleteMapping("/delete")
    public ResponseResult<Void> deleteSimple(@RequestParam List<Long> simpleIdList){
        return simpleService.deleteSimple(simpleIdList);
    }

    public static void main(String[] args) {
        List<SimpleVo> simpleVoList = new ArrayList<>();
        SimpleVo simpleVo = new SimpleVo();
        simpleVo.setSimpleId(1L);
        simpleVo.setSimpleName("测试");
        simpleVo.setSimpleDesc("描述");
        simpleVo.setSimpleStatus(0);
        simpleVoList.add(simpleVo);
        System.out.println(simpleVoList instanceof Page);
    }
}
